package com.test.common.publishingrealize;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class PublishingVehicleTracker {
        private final Map<String, PublishedPoint> locations;
        private final Map<String, PublishedPoint> unmodifiableMap;

        public PublishingVehicleTracker(Map<String, PublishedPoint> locations) {
                this.locations = new ConcurrentHashMap<String, PublishedPoint>(locations);
                this.unmodifiableMap = Collections.unmodifiableMap(this.locations);
        }

        public Map<String, PublishedPoint> getLocations() {
                return unmodifiableMap;
        }

        public PublishedPoint getLocation(String id) {
                return locations.get(id);
        }

        public void setLocation(String id, int x, int y) {
                if (!locations.containsKey(id))
                        throw new IllegalArgumentException("invalid vehicle name");
                locations.get(id).set(x, y);
        }

}
